home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / AECUR100.ARJ / CALCPOPY.C < prev    next >
C/C++ Source or Header  |  1990-03-08  |  2KB  |  65 lines

  1. /*------------------------------------------------------------
  2.  * 
  3.  *  calcpopyx.c
  4.  * 
  5.  *  copyright (c) 1987,88,89,90 J. Alan Eldridge
  6.  * 
  7.  *  calculate where to put a popup box relative to the
  8.  *  current cursor position / input field location
  9.  * 
  10.  *  returns ERR if you can't pop up without covering the cursor
  11.  *  otherwise it returns OK
  12.  * 
  13.  *----------------------------------------------------------*/
  14.  
  15. #include "curses.h"
  16.  
  17. #define MAX_DISTANCE 10
  18. #define MIN_DISTANCE 1
  19.  
  20. int
  21. calcpopyx(rows, cols, cury, minx, maxx, yp, xp)
  22. int rows, cols, minx, maxx, *yp, *xp;
  23. {
  24.     int y0, y1, x0, x1, dist;
  25.  
  26.     for (dist = MAX_DISTANCE; dist >= MIN_DISTANCE; dist--) {
  27.         /* look right */
  28.         x0 = maxx + dist;
  29.         x1 = x0 + cols - 1;
  30.         y0 = (LINES - rows) / 2;
  31.         y1 = y0 + rows - 1;
  32.         if (x1 <= COLS)
  33.             break;
  34.         /* look left */
  35.         x1 = minx - dist;
  36.         x0 = x1 - cols + 1;
  37.         if (x0 >= 0)
  38.             break;
  39.         /* look above */
  40.         x0 = (COLS - cols) / 2;
  41.         x1 = x0 + cols - 1;
  42.         y1 = cury - dist;
  43.         y0 = y1 - rows + 1;
  44.         if (y0 >= 0)
  45.             break;
  46.         /* look below */
  47.         y0 = cury + dist;
  48.         y1 = y0 + rows - 1;
  49.         if (y1 <= LINES)
  50.             break;
  51.     }
  52.     if (dist < MIN_DISTANCE) {
  53.         /* center of screen */
  54.         *xp = (COLS - cols) / 2;
  55.         *yp = (LINES - rows) / 2;
  56.         return ERR;
  57.     } else {
  58.         *xp = x0;
  59.         *yp = y0;
  60.         return OK;
  61.     }
  62. }
  63.  
  64.  
  65.